//
//  JSLoginApi.swift
//  fho
//
//  Created by 郭颢源 on 2021/4/23.
//

import UIKit


    enum JSLoginApi {
        case realtimeWeather(cityId:String)
        case getorder(cityId:String)
        case login(name:String,pwd:String,code:String)
        case register(name:String,pwd:String,code:String)
        case logout(name:String,token:String)
    }

    extension JSLoginApi: BaseTargetType {
        // 对应的不同API path
        var path: String {
            switch self {
            case .login(name:_,pwd:_,code:_):
                return ""
            case .register(name:_,pwd:_,code:_):
                return ""
            case .logout(name:_,token:_):
                return ""
            case .realtimeWeather(cityId: _):
                return "/lis/danhao/index1"
            case .getorder(cityId: _):
                return ""
            }
            return ""
        }
        
        // 请求类型
        public var method: Moya.Method {
            switch self {
            
            case .realtimeWeather(cityId: _):
                return .post
            case .getorder(cityId: _):
                return .post
            default:
                return .get
            }
        }
        
        /// 请求任务事件（这里附带上参数）
        public var task: Task {
            switch self {
            case .login(name:let name,pwd:let pwd,code:let code):
                let params = ["name":name,"pwd":pwd,"code":code]
                
                return .requestParameters(parameters:params, encoding:URLEncoding.default)
            case .register(name:let name,pwd:let pwd,code:let code):
                let params = ["name":name,"pwd":pwd,"pwd":code]
                
                return .requestParameters(parameters:params, encoding:URLEncoding.default)
            case .logout(name:let name,token:let token):
                let params = ["name":name,"token":token]
                
                return .requestParameters(parameters:params, encoding:URLEncoding.default)
        
            case .realtimeWeather(cityId: let cityId):
                return .requestParameters(parameters: ["type":cityId], encoding: URLEncoding.default)
    //        case .getorder(cityId: let cityId):
    //            return .requestPlain
            default:
                return .requestPlain
            }
            
        }
        
    }

